home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / hypercrd / xcmds / dvlprstc.hqx / Developer Stack 1.3r / card_45142.txt < prev    next >
Text File  |  1991-04-30  |  8KB  |  179 lines

  1. -- card: 45142 from stack: in.3r
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 2612
  5. -- name: Progress
  6.  
  7.  
  8. -- part 1 (button)
  9. -- low flags: 00
  10. -- high flags: A003
  11. -- rect: left=60 top=234 right=256 bottom=179
  12. -- title width / last selected line: 0
  13. -- icon id / first selected line: 0 / 0
  14. -- text alignment: 1
  15. -- font id: 0
  16. -- text size: 12
  17. -- style flags: 0
  18. -- line height: 16
  19. -- part name: Install
  20. ----- HyperTalk script -----
  21. on mouseUp
  22.   if the optionkey is down then pass mouseup
  23.   put installres(XCMD,field "name") into it
  24.   put installres(DLOG,"Working") into it
  25.   put installres(DITL,"Working") into it
  26.   put installres(PICT,"Scale") into it
  27.   put installres(ICON,"Note") into it
  28.   put installres(cicn,"Color Note") into it
  29. end mouseUp
  30.  
  31.  
  32.  
  33. -- part 2 (button)
  34. -- low flags: 00
  35. -- high flags: A004
  36. -- rect: left=191 top=231 right=282 bottom=268
  37. -- title width / last selected line: 0
  38. -- icon id / first selected line: 27056 / 27056
  39. -- text alignment: 1
  40. -- font id: 0
  41. -- text size: 12
  42. -- style flags: 0
  43. -- line height: 16
  44. -- part name: Try it...
  45. ----- HyperTalk script -----
  46. on mouseUp
  47.   global ProgressPointer,RemoveProgress
  48.   set cursor to watch
  49.   put "Now performing some time-consuming operation." into promptString
  50.   Progress 1,promptString
  51.   repeat with i=1 to 100
  52.     Progress 2,i
  53.     wait 3
  54.   end repeat
  55.   --wait 1 seconds
  56.   Progress 3
  57. end mouseUp
  58.  
  59.  
  60.  
  61. -- part contents for background part 13
  62. ----- text -----
  63. 41
  64.  
  65. -- part contents for background part 30
  66. ----- text -----
  67. XCMD
  68.  
  69. -- part contents for background part 2
  70. ----- text -----
  71. Progress
  72.  
  73. -- part contents for background part 3
  74. ----- text -----
  75. Up until now, the only method of providing visual feed-back to the user during time intensive operations was to do such things as animate the cursor or plug "update" comments into the message box during the execution of time-consuming scripts.
  76.  
  77. Progress XCMD provides a much more elegant alternative for providing visual feed-back that everything is proceeding normally.
  78.  
  79. It displays a dialog containing a graphic display with a "diamond" symbol that moves along a scale to indicate "Percent Complete".  The dialog box contains your prompt string as to what is going on and can be positioned anywhere on the screen 
  80. (it is centered on the card window by default).
  81.  
  82. Progress XCMD took a certain amount of effort to create, get functioning and debugged.  For those of you who write monster scripts this external command will go a long way toward helping you create a product that looks very polished.
  83.  
  84. If Progress XCMD is useful to you and you wish to use it, please feel free to use it. I only ask for a $5 registration to support the development of more XCMDs and XFCNs.  Believe me, I have more wonderous external commands up my sleeve, and it is based on the support of other users that these things get done.
  85.  
  86. Send $5 to
  87. Jay Hodgdon
  88. 587 Cutwater Lane
  89. Foster City, CA  94404
  90.  
  91. For feedback and bug reports 
  92. (God forbid!) I can be reached at:
  93.  
  94. CIS:  70411,63
  95. GEnie: JHodgdon
  96. MacNet:  HodgdonJ
  97.  
  98.  
  99. -- part contents for background part 10
  100. ----- text -----
  101. Syntax:
  102.  
  103. The dialog is first displayed by this call to the XCMD:
  104.  
  105. Progress 1, <prompt string>
  106.  
  107. where <prompt string> contains your comments regarding what is going on:
  108. "Now stripping all non-numbers from the phone book." or "Now locating all occurances of "thou" in Hamlet..."
  109.  
  110. When Progress XCMD is first called the 
  111. "diamond indicator" is initially set to 0.
  112.  
  113. This form of Progress XCMD can also accept two other OPTIONAL parameters:
  114.  
  115. Progress 1,<prompt string>[,<top coordinate>,<left coordinate>]
  116.  
  117. This allows you to modify the location of the dialog window by providing a top left point at which the dialog will be placed.  If the optional parameters are omitted, the dialog will be centered within the card window's boundaries.
  118.  
  119. The diamond indicator is then moved along the length of the "Percent Complete" scale by calling:
  120.  
  121.      Progress 2,<indicator location>
  122.  
  123. within a repeat loop.
  124.  
  125. The <indicator location> should be a WHOLE number between 0 and 100, as these coorespond to the units on the scale.  Use the HyperTalk function ROUND to round fractions to the nearest whole number.
  126.  
  127. Examples:
  128.    round(11.5) returns 11
  129.   round(11.51) returns 12
  130.  
  131. The dialog is finally removed from the screen and disposed of by calling:
  132.  
  133.    Progress 3
  134.  
  135. To get the diamond to move across the scale you must repeatedly call Progress 2,<indicator location> during the execution of your script.  You can imagine doing this in a variety of ways.
  136.  
  137. Now for more on those global variables:
  138.  
  139. global ProgressPointer,RemoveProgress
  140.  
  141. In your HyperTalk script you initially display the Progress dialog by calling "Progress 1,<string>".  This first call to the external simply displays the dialog and allocates some memory for the it.  In order for the dialog to be subsequently modified (i.e., to have the diamond move along the scale), the pointer to the dialog in memory must be retrieved.  This is accomplished by storing the dialog's pointer (between calls to the external) in the HyperTalk global variable "ProgressPointer".  You don't have to worry about loading the variable yourself.  This business is automatically taken care of when the XCMD is first called.
  142.  
  143. When you call "Progress 2,<integer>" or "Progress 3", the XCMD recovers the location of the dialog in memory (its pointer) by retrieving the information from "ProgressPointer".  You don't have to worry about passing the contents of the global on to the XCMD.  In fact, all you need to do is to NOT put anything of your own into the global variable "ProgressPointer", or you will surely bomb your Mac (because you'll confuse the XCMD).
  144.  
  145. Calling "Progress 2,<integer>" retrieves the pointer to the dialog from the global variable and moves the diamond to the new location on the scale.  Calling "Progress 3" retrieves the dialog's pointer, gets rid of the dialog and then disposes of the memory used by the dialog.
  146.  
  147. You can imagine the consequences of calling Progress 2 or Progress 3 without first having called Progress 1. You would be attempting to modify or dispose of memory used by SOMETHING OTHER than the Progress dialog.  Your Mac would crash and burn.  In order to prevent you wild and crazy people from doing that, calling Progress 1 also loads a second HyperTalk global variable, called 
  148. "RemoveProgress".  It sets this variable to TRUE.
  149.  
  150. Then when you call Progress 2 it will do something only if the global variable RemoveProgress is TRUE.  The same goes for Progress 3.  It will only attempt to dispose of this memory if RemoveProgress is TRUE and will then set RemoveProgress to FALSE (so that it cannot dispose of memory a second time).
  151.  
  152. Once again, don't change the variable RemoveProgress on your own unless you like to bomb your Mac.
  153.  
  154. Last thing:
  155. There is an additional reason for having the second global variable RemoveProgress.  If your end user becomes impatient and hits command-. to abort a time-consuming handler, the call to the XCMD "Progress 3", to remove the dialog, probably will not have occured.  To prevent the dialog from hanging around after such an abort, put the following idle script in your background or stack:
  156.  
  157. on idle
  158.    global ProgressPointer,RemoveProgress
  159.    if RemoveProgress is TRUE then
  160.       Progress 3
  161.       put FALSE into RemoveProgress
  162.    end if
  163.    pass idle
  164. end idle
  165.  
  166. In this situation, RemoveProgress could ONLY be TRUE if someone had aborted a handler in which Progress 1 was called and Progress 3 was not.
  167.  
  168. The resource components of Progress XCMD are:
  169.  
  170. XCMD "Progress" ID 2155  
  171. DLOG "Working" ID 2155
  172. DITL "Working" ID 2155            
  173. PICT "Scale" ID 2155
  174. ICON "Note"  ID 2222
  175. cicn "Color Note" ID 2222
  176.  
  177. The cicn resource is strictly optional.  If you have a color monitor the cicn (for color icon) will be displayed in place of an ICON of the same ID number.  This is no big deal but my feeling is that any way I can squeeze some color into HyperCard is worth the effort.  If you don't have a color monitor this resource is ignored (so it doesn't hurt).
  178.  
  179.